package util;

import java.math.BigDecimal;
import java.util.List;

public class Util {

    private static BigDecimal total;

    public static BigDecimal paycounts1(Fruits apple, Fruits strawberry) {
        BigDecimal applePrice = apple.getPrice().multiply(new BigDecimal(apple.getNum()));
        BigDecimal strawberryPrice = strawberry.getPrice().multiply(new BigDecimal(strawberry.getNum()));
        total = applePrice.add(strawberryPrice);
        return total;
    }

    public static BigDecimal paycounts2(Fruits apple, Fruits strawberry, Fruits mango) {
        BigDecimal applePrice = apple.getPrice().multiply(new BigDecimal(apple.getNum()));
        BigDecimal strawberryPrice = strawberry.getPrice().multiply(new BigDecimal(strawberry.getNum()));
        BigDecimal mangoPrice = mango.getPrice().multiply(new BigDecimal(mango.getNum()));
        total = applePrice.add(strawberryPrice).add(mangoPrice);
        return total;
    }

    public static BigDecimal paycounts3(Fruits apple, Fruits strawberry, Fruits mango) {
        BigDecimal applePrice = apple.getPrice().multiply(new BigDecimal(apple.getNum()));
        BigDecimal strawberryPrice = strawberry.getPrice().multiply(new BigDecimal(strawberry.getNum())).multiply(new BigDecimal(0.8));
        strawberryPrice = strawberryPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
        BigDecimal mangoPrice = mango.getPrice().multiply(new BigDecimal(mango.getNum()));
        total = applePrice.add(strawberryPrice).add(mangoPrice);
        return total;
    }

    public static BigDecimal paycounts4(Fruits apple, Fruits strawberry, Fruits mango) {
        BigDecimal applePrice = apple.getPrice().multiply(new BigDecimal(apple.getNum()));
        BigDecimal strawberryPrice = strawberry.getPrice().multiply(new BigDecimal(strawberry.getNum())).multiply(new BigDecimal(0.8));
        BigDecimal mangoPrice = mango.getPrice().multiply(new BigDecimal(mango.getNum()));
        total = applePrice.add(strawberryPrice).add(mangoPrice);
        BigDecimal discount = total.divide(new BigDecimal(100)).setScale(0, BigDecimal.ROUND_HALF_UP);
        total = total.subtract(discount.multiply(new BigDecimal(10))).setScale(2, BigDecimal.ROUND_HALF_UP);
        return total;
    }

    /**
     * 5.1 新增梨子
     * @param apple
     * @param strawberry
     * @param mango
     * @param pear
     * @return
     */
    public static BigDecimal paycounts6(Fruits apple, Fruits strawberry, Fruits mango, Fruits pear) {
        BigDecimal applePrice = apple.getPrice().multiply(new BigDecimal(apple.getNum()));
        BigDecimal strawberryPrice = strawberry.getPrice().multiply(new BigDecimal(strawberry.getNum())).multiply(new BigDecimal(0.8));
        BigDecimal mangoPrice = mango.getPrice().multiply(new BigDecimal(mango.getNum()));
        BigDecimal pearPrice = pear.getPrice().multiply(new BigDecimal(pear.getNum()));
        total = applePrice.add(strawberryPrice).add(mangoPrice).add(pearPrice);
        BigDecimal discount = total.divide(new BigDecimal(100)).setScale(1, BigDecimal.ROUND_HALF_UP);
        System.out.println(discount);

        total = total.subtract(discount.setScale( 0, BigDecimal.ROUND_DOWN ).multiply(new BigDecimal(10))).setScale(2, BigDecimal.ROUND_HALF_UP);
        return total;

    }

    public static BigDecimal getCost(List<Fruits> fruitsList) {
        BigDecimal total = new BigDecimal(0);
        if (fruitsList == null) {
            return null;
        }

        if (fruitsList.size() <= 0) {
            return total;
        }

        for (Fruits fruits : fruitsList) {
            BigDecimal strawberryPrice = fruits.getPrice().multiply(new BigDecimal(fruits.getNum()));
            total = total.add(strawberryPrice);
        }
        return total;
    }

    /**
     * 5.1 +
     */
    public static BigDecimal paycounts5(Fruits apple, Fruits strawberry, Fruits mango, Fruits Pear) {
        BigDecimal applePrice = apple.getPrice().multiply(new BigDecimal(apple.getNum()));
        BigDecimal strawberryPrice = strawberry.getPrice().multiply(new BigDecimal(strawberry.getNum()));
        BigDecimal mangoPrice = mango.getPrice().multiply(new BigDecimal(mango.getNum()));
        BigDecimal PearPrice = Pear.getPrice().multiply(new BigDecimal(Pear.getNum()));
        total = applePrice.add(strawberryPrice).add(mangoPrice).add(PearPrice);
        return total;
    }
}
